<?php

declare(strict_types=1);

namespace Plugin\Attractions\AttractionManagement\Service;

use App\Service\IService;
use Plugin\Attractions\AttractionManagement\Model\Attraction;
use Plugin\Attractions\AttractionManagement\Repository\AttractionRepository;

/**
 * @extends IService<Attraction>
 */
final class AttractionService extends IService
{
    public function __construct(
        protected readonly AttractionRepository $repository,
    ) {}

    public function create(array $data): bool
    {
        return $this->repository->create([
            'name' => $data['name'],
            'intro_title' => $data['introTitle'],
            'intro' => $data['intro'],
            'cover_id' => $data['coverId'],
            'status' => $data['status'],
            'address' => $data['address'],
            'phone' => $data['phone'],
            'open_time' => $data['openTime'],
            'close_time' => $data['closeTime'],
        ]) ? true : false;
        
    }

    public function delete(int $id) : int
    {
        $attraction = $this->repository->findById($id);
        if ($attraction) {
            $this->resourceRepository->deleteById($attraction->cover_id);
        }
        return $this->repository->deleteById($id);
    }

    public function update(int $ids, array $data): bool
    {
        return $this->repository->updateById($ids, $data);
    }

    public function get(int $id): array
    {
        return $this->repository->detail($id);
    }

    public function list($params): array
    {
        return $this->repository->showListPage($params);
    }
}
